<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8"/>
    <title>新增</title>

    <!-- CSS -->
    <link rel="stylesheet" href="../../static/plugins/layui/css/layui.css" th:href="@{plugins/layui/css/layui.css}"/>
    <link rel="stylesheet" href="../../static/mycss/common.css" th:href="@{mycss/main.css}"/>

</head>
<body>
<input type="hidden" name="uuid"/>
<div>
    <div style="margin:10px;">
        <form class="layui-form">
            <div class="layui-form-item">
                <blockquote class="layui-elem-quote">
                    <button class="layui-btn" id="demoSave" lay-submit="" lay-filter="*">保存</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </blockquote>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">d1</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="d1" lay-verify="required" placeholder="d1"/>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">d2</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="d2" placeholder="d2"/>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">d3</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input date" readonly name="d3" placeholder="yyyy-MM-dd"/>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">d4</label>
                    <div class="layui-input-inline">
                        <select name="d4">
                            <option value="">---请选择---</option>
                            <option value="0">分类1</option>
                            <option value="1">分类2</option>
                            <option value="2">分类3</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">d5</label>
                    <div class="layui-input-inline">
                        <select name="d5">
                            <option value="">---请选择---</option>
                            <option value="0">来源1</option>
                            <option value="1">来源2</option>
                            <option value="2">来源3</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">d6</label>
                    <div class="layui-input-inline">
                        <select name="d6">
                            <option value="">---请选择---</option>
                            <option value="0">来源1</option>
                            <option value="1">来源2</option>
                            <option value="2">来源3</option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">d7</label>
                <div class="layui-input-block">
                    <input type="radio" name="d7" value="1" title="男" checked>
                    <input type="radio" name="d7" value="0" title="女">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">dX</label>
                <div class="layui-input-block">
                    <input type="checkbox" name="d8" title="d8" checked>
                    <input type="checkbox" name="d9" title="d9">
                    <input type="checkbox" name="d10" title="d10">
                </div>
            </div>
            <div class="layui-form-item ">
                <label class="layui-form-label">d11</label>
                <div class="layui-input-block">
                    <textarea class="layui-textarea" name="d11" lay-verify="" placeholder="d9"></textarea>
                </div>
            </div>
            <div class="layui-form-item ">
                <label class="layui-form-label">d12</label>
                <div class="layui-input-block">
                    <textarea class="layui-textarea" name="d12" placeholder="d10"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">附件上传：</label>
                <div class="layui-input-block">
                    <div class="file_upload" style="width: 80px;height: 80px;background-color: #93D1FF">
                        <i class="layui-icon" style="font-size: 80px; color: #1E9FFF;">&#xe654;</i>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

<!-- JS -->
<script type="text/javascript" src="../../static/plugins/layui/layui.js" th:src="@{plugins/layui/layui.js}"></script>
<script>
    layui.use(['form', 'laydate', 'layer', 'upload'], function () {
        var $ = layui.$;
        var form = layui.form;
        var laydate = layui.laydate;
        var layer = layui.layer;

        /**
         * 表单提交 监听
         */
        form.on('submit(*)', function (data) {
            var subInfo;//提交信息
            //表单验证
            if(1!=1){
                layer.msg('提示信息',{icon:5,time:1000});
                return false;
            }else {
                subInfo = JSON.stringify(data.field);
                //提交
                $.ajax({
                    url: 'demo/demoAdd',
                    type: 'post',
                    data: {subInfo: subInfo},
                    dataType: 'text',//服务器返回的数据类型。
                    success: function (result) {
                        layer.msg("保存成功", {icon: 1, time: 1500});
                    },
                    error: function (e) {
                        layer.msg("出现异常", {icon: 5, time: 1000});
                    }
                });
            }
            //注：此处必须有这个，因为这里我用了自己的ajax来提交表单，如果不return false，form监听程序本身也会触发提交，可能会出现莫名奇妙的错误
            return false;
        });

        //日期框渲染，同时绑定多个输入框
        lay('.date').each(function () {
            laydate.render({
                elem: this,
                trigger: 'click',
                format: 'yyyy-MM-dd'
            });
        });

        //弹出附件上传框
        $('.file_upload').click(function(){
            layer.open({
                type: 2,
                title: '附件列表',
                content: '../mydemo/fileupload.html',
                area: ['800px', '80%'],
                resize:false,//是否允许拉伸
                maxmin: false, //开启最大化最小化按钮
                shadeClose: false,
                shade : 0.6
            });
        });
    });
</script>

</body>
</html>